package com.atguigu.yygh.hosp.controller.api;

import com.atguigu.yygh.hosp.bean.Result;
import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.utlis.HttpRequestHelper;
import com.atguigu.yygh.model.hosp.Department;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;


@RestController
@RequestMapping("/api/hosp")
public class ApiDepartmentController {

    @Resource
    private DepartmentService departmentService;

    /**
    * @description:科室列表里面的删除功能
    * @author :又菜又爱玩的→速趴塞亚锦←
    * @create :2023/5/17
    * @param  :1.8
    */
    @PostMapping("/department/remove")
    public Result remove(HttpServletRequest httpServletRequest){
        Map<String, Object> stringObjectMap = HttpRequestHelper.switchMap(httpServletRequest.getParameterMap());
        //signkey验证
        departmentService.remove(stringObjectMap);

        return Result.ok();
    }
    /**
     * @description:科室的上传完成做（页面显示）功能    请求的是科室信息
     * @author :又菜又爱玩的→速趴塞亚锦←
     * @create :2023/5/17
     * @param  :1.8
     */
    @PostMapping("/department/list")
    public Result<Page> getDepartmentPage(HttpServletRequest httpServletRequest){
        Map<String, Object> stringObjectMap = HttpRequestHelper.switchMap(httpServletRequest.getParameterMap());
        //1.signkey验证://做一个MD5是否一致的if判断等等。。。。和HospitalController一样
        Page<Department> page= departmentService.getDepartmentPage(stringObjectMap);
        return Result.ok(page);
    }
    /**
     * @description:科室的上传（添加）功能
     * @author :又菜又爱玩的→速趴塞亚锦←
     * @create :2023/5/17
     * @param  :1.8
     */
    @PostMapping("/saveDepartment")
    public Result saveDepartment(HttpServletRequest request){
        Map<String, Object> stringObjectMap = HttpRequestHelper.switchMap(request.getParameterMap());
        //1.signkey验证://做一个MD5是否一致的if判断等等。。。。和HospitalController一样
        departmentService.saveDepartment(stringObjectMap);


        return Result.ok();
    }
}
